<?php

    // Include domain-specific classes
    require dirname(__FILE__) . DIRECTORY_SEPARATOR . '_include.php';
    
    try {
    
        //----------------------------------------------------------------------
        // Initialise domain objects
        
        // The Master Datagateway will be the base object to amend functionality.
        
        $obj_datagateway = new DataGateway_Master();
        
        // The Notifier can be used to publish an email to the Development Team
        // when an exception has occurred.
        
        $obj_notifier = new Notifier();
    
    
        //----------------------------------------------------------------------
        // Create weaved delegator
        
        // Encapsulate the base object within a Weaved Delegator; this will 
        // provide the means to add functionality when an exception is caught.
        
        $obj = new ClassStructure_Weaved_Delegator($obj_datagateway);
        
        // Define a "pointcut" which will be used to match methods in which to
        // weave functionality - in this case, it is all base object methods.
        $obj_pointcut = new ClassStructure_PointCut();
        $obj_pointcut->setPattern('/.*/');
        
        // Instruct the Weaved Delegator to invoke the publishException() method 
        // when the base object has caught an exception on the target methods.
        
        $obj->__weaveAdviceOnException(
            array($obj_notifier, 'publishException'), 
            $obj_pointcut
        );
        
        
        //----------------------------------------------------------------------
        // Test functionality
        
        $obj->insertPressTitle(array(
            'title_name' => 'Financial Times',
            'categories' => array(1)
        ));
        
        echo "\n\n";
        
        //----------------------------------------------------------------------
        // Expose structure
        
        echo ClassStructure_UtilityFunctions::getObjectSignature($obj);
        echo "\n";
        echo ClassStructure_UtilityFunctions::getAdviceSignature($obj, 'insertPressTitle');
        
        
    } catch (Exception $obj_exception) {
        print_r($obj_exception);
    }
